var Api = require('../../utils/api.js');
var util = require('../../utils/util.js');
var Auth = require('../../utils/auth.js');

var wxApi = require('../../utils/wxApi.js')
var wxRequest = require('../../utils/wxRequest.js');
var app = getApp();
var webSiteName= config.getWebsiteName;
var domain =config.getDomain
import config from '../../utils/config.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    windowHeight:'100%',
    title:'LINMOPPF质保单1',
    userInfo:{},
    info:{}, 
    num: 0,
    numList: [
        { 
            title: '门店录入'
        },
        {
            title: '服务商审核'
        },
        {
            title: '总部审核-生效'
        }
    ],
  }, 

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var self = this;
    //console.log(self.data);debugger;
    wx.getSystemInfo({
      success: (result) => {
        self.setData({
          windowHeight:result.windowHeight,
          windowWidth:result.windowWidth
        })
        if(result.inFinChat)
        {          
          self.setData({inFinChat:result.inFinChat})          
        }
        else{          
          Auth.setUserInfoData(self);
          console.log('开始');
          console.log(self.data);
          Auth.checkLogin(self);
          self.setData({copyright: getApp().globalData.copyright})
          Auth.checkSession(self, 'isLoginNow');
        }
      },
    }) 
    
    var that = this;
    // console.log(self.data.userInfo);
    wx.request({
      url: 'https://a.ygtape.com.cn/index.php/qualityassurance/index/info',
      method:'POST',
      data:{
        id:options.id,
        mobile:self.data.userInfo.user_mobile,
        token:self.data.userInfo.token,
      },
      header:{
        'content-type':'application/x-www-form-urlencoded'
      },
      success:function(res){
        console.log(res.data.info)
        //获取info 判断这个账号能不能审核
        if(res.data.status == 200){
          let num =  res.data.info.status - 1;
          var title = '5555';
          console.log(res.data.info.type);
         switch(res.data.info.type){
             case 1:  
                title = '漆面膜质保单-'+res.data.info.num;
                 break;
            case 2: 
                title = '窗膜质保单-'+res.data.info.num;
                break; 
            case 3: 
                title = '改色膜质保单-'+res.data.info.num;
                break;
            default:
                    title = '';
                break;
         }
         console.log(title);
          that.setData({ 
            title:title,
            num:num,   
            info:res.data.info 
          })
        }else{
            
        }

      }

      
    }) 
  
    //需要用户登录
    //  var self = this;
    wx.getSystemInfo({
      success: (result) => {
        self.setData({
          windowHeight:result.windowHeight,
          windowWidth:result.windowWidth
        })
      },
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },

  shenhetongguo:function(e){
    var self = this;
    //console.log(self.data);debugger;
    wx.request({
      url: 'https://a.ygtape.com.cn/index.php/qualityassurance/index/audit',
      method:'POST',
      data:{
          id:self.data.info.id, 
          mobile:self.data.userInfo.user_mobile,
          token:self.data.userInfo.token
        },
      header:{
        'content-type':'application/x-www-form-urlencoded'
      },
      success:function(res){
        if(res.data.status == 200){
          wx.showToast({title:'操作成功',duration: 2000});
          self.setData({
            'info.status':2
          })
        }else{
          wx.showToast({title:'操作失败',icon:'error',duration: 2000});
          wx.navigateBack();
        }

      }
    })
  },

  bohui:function(e){
    var self = this;
    //console.log(self.data);debugger;
    wx.request({
      url: 'https://a.ygtape.com.cn/index.php/qualityassurance/index/bohui',
      method:'POST',
      data:{
          id:self.data.info.id, 
          mobile:self.data.userInfo.user_mobile,
          token:self.data.userInfo.token
        },
      header:{
        'content-type':'application/x-www-form-urlencoded'
      },
      success:function(res){
        if(res.data.status == 200){
          wx.showToast({title:'操作成功',duration: 2000});
          self.setData({
            'info.status':8
          })
        }else{
          wx.showToast({title:'操作失败',icon:'error',duration: 2000});
          wx.navigateBack();
        }

      }
    })
  }
})